import {
  getInviteCode
} from '../../api/index.js';

Page({
  data: {
    shareTitle: '邀请有礼',
    shareImage: '/images/yqhy.png',
    inviteCode: ''
  },

  getInviteCode() {
    getInviteCode().then(res => {
      console.log(res, 'res');
      this.setData({
        inviteCode: res.result
      });
    });
  },

  onLoad() {
    this.getInviteCode();
  },

  // 转发给朋友（右上角菜单或按钮触发）
  onShareAppMessage() {
    return {
      title: this.data.shareTitle,
      imageUrl: this.data.shareImage,
      path: `/pages/me/index?inviteCode=${this.data.inviteCode}`, // 分享后进入的页面
    }
  },

  // 分享到朋友圈（按钮触发）
  onShareTimeline() {
    return {
      title: this.data.shareTitle,
      imageUrl: this.data.shareImage,
      query: `from=timeline&inviteCode=${this.data.inviteCode}` // 可选，分享参数
    }
  },

  // 自定义按钮分享
  handleShare() {
    console.log(this.data.inviteCode, 'this.data.inviteCode');
    
    wx.showShareImageMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    });
  }
})